package Model;

/**
 * Classe responsavel pelo dados necessarios para gerar os itens na tela. 
 * 
 * @author Edjane Catolle, Igor Henrique, Luiz Augusto, Vladmir Chicarolli
 * @version 1.0.0
 * @since 06/05/2011
 */

import java.awt.Point;
import java.awt.Rectangle;
import java.util.HashMap;
import java.util.Random;

public class ItemBase 
{
	public static ItemBase _itemBase = null;
	private HashMap<Integer, Rectangle> positionsItem;
	private Rectangle position;
	private int index;
	
	public ItemBase()
	{	
		possiblesPositions();
	}
	
	/**
	 * Insere uma posicao para o intem gerado
	 */
	private void possiblesPositions()
	{
		positionsItem = new HashMap<Integer, Rectangle>();
		positionsItem.put(positionsItem.size() + 1, (new Rectangle(7 * 50, 0, 50, 50)));
		positionsItem.put(positionsItem.size() + 1, (new Rectangle(6 * 50, 7 * 50, 50, 50)));
		positionsItem.put(positionsItem.size() + 1, (new Rectangle(10 * 50, 4 * 50, 50, 50)));
		positionsItem.put(positionsItem.size() + 1, (new Rectangle(9 * 50, 9 * 50, 50, 50)));
		positionsItem.put(positionsItem.size() + 1, (new Rectangle(3 * 50, 4 * 50, 50, 50)));
		
		SortPositions();		
	}
	
	/**
	 * Sorteia posicoes possiveis para os itens gerados
	 */
	public void SortPositions()
	{
		index = new Random().nextInt(5);
		this.position = positionsItem.get(index);
		
	}
	
	/**
	 * Retangulo do item gerado
	 * @return - o retangulo do item
	 */
	public Rectangle GetTile()
	{
		return positionsItem.get(index);
	}
	
	/**
	 * Posicao do item na tela
	 * @return - a posicao do item na tela
	 */
	public Point GetTilePoint()
	{
		if(position == null)
		{
			return null;
		}
		return new Point(this.position.y, this.position.x);
	}
	
	public static ItemBase ItemManager()
	{
		if(_itemBase == null)
		{
			_itemBase = new ItemBase();
		}
		return _itemBase;
	}	
}
